<?php

namespace JLPay\Models\BaseData;

use JLPay\Models\BaseRequest;

/**
 * 地区码查询请求
 */
class RegionListRequest extends BaseRequest
{
    /**
     * API接口路径
     */
    public const API_URL = '/open/base/data/region/list';

    protected ?string $regionCode = null;
    protected ?string $regionName = null;
    protected ?string $parentCode = null;
    protected ?string $regionRank = null;
    protected ?int $limit = null;
    protected ?int $offset = null;

    /**
     * 设置地区码
     *
     * @param string $regionCode
     * @return self
     */
    public function setRegionCode(string $regionCode): self
    {
        $this->regionCode = $regionCode;
        return $this;
    }

    /**
     * 设置地区名称
     *
     * @param string $regionName
     * @return self
     */
    public function setRegionName(string $regionName): self
    {
        $this->regionName = $regionName;
        return $this;
    }

    /**
     * 设置上级地区码
     *
     * @param string $parentCode
     * @return self
     */
    public function setParentCode(string $parentCode): self
    {
        $this->parentCode = $parentCode;
        return $this;
    }

    /**
     * 设置地区等级：1 省 2市 3区
     *
     * @param string $regionRank 地区等级，1 省 2市 3区
     * @return self
     */
    public function setRegionRank(string $regionRank): self
    {
        $this->regionRank = $regionRank;
        return $this;
    }

    /**
     * 设置每页记录数
     *
     * @param int $limit
     * @return self
     */
    public function setLimit(int $limit): self
    {
        $this->limit = $limit;
        return $this;
    }

    /**
     * 设置偏移量
     *
     * @param int $offset 偏移量，pageSize = offset / limit + 1，示例值：如果limit为10，则第二页offset传11
     * @return self
     */
    public function setOffset(int $offset): self
    {
        $this->offset = $offset;
        return $this;
    }

    /**
     * 转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        $data = parent::toArray();
        
        if ($this->regionCode !== null) {
            $data['region_code'] = $this->regionCode;
        }
        if ($this->regionName !== null) {
            $data['region_name'] = $this->regionName;
        }
        if ($this->parentCode !== null) {
            $data['parent_code'] = $this->parentCode;
        }
        if ($this->regionRank !== null) {
            $data['region_rank'] = $this->regionRank;
        }
        if ($this->limit !== null) {
            $data['limit'] = $this->limit;
        }
        if ($this->offset !== null) {
            $data['offset'] = $this->offset;
        }
        
        return $data;
    }
} 